﻿<template>
  <a-drawer
    :title="title"
    width="90%"
    :visible="visible"
    @close="
      () => {
        this.visible = false
      }
    "
  >
    <div style="margin-bottom: 20px">
      <a-radio-group v-model="applyType" @change="changeViewDataList">
        <a-radio :value="0">未申请</a-radio>
        <a-radio :value="-1">已申请</a-radio>
      </a-radio-group>
    </div>
    <a-table
      ref="table"
      :scroll="{ y: 'calc(100vh - 200px)', x: tableWidth }"
      :columns="columnsPreview"
      :dataSource="data"
      :pagination="false"
      :loading="loadingPreview"
      :bordered="true"
      size="small"
    >
    </a-table>
    <div
      :style="{
        position: 'absolute',
        right: 0,
        bottom: 0,
        width: '100%',
        borderTop: '1px solid #e9e9e9',
        padding: '4px 16px',
        background: '#fff',
        textAlign: 'right',
        zIndex: 1,
      }"
    >
      <a-button
        @click="
          () => {
            this.visible = false
          }
        "
        >取消</a-button
      >&nbsp;
    </div>
  </a-drawer>
</template>

<script>
const toThousands = function (data) {
  if (data != null) {
    return data.toFixed(2).replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
  } else {
  }
}
const columnsPreview = [
  {
    title: '序号',
    dataIndex: 'Id',
    customRender: (text, row, index) => {
      return index + 1
    },
    width: '50px',
  },
  { title: '出库单号', dataIndex: 'code', width: '150px', align: 'right' },
  { title: '货物编码', dataIndex: 'ventorycode', width: '100px', align: 'right' },
  { title: '货物名称', dataIndex: 'ventoryname', width: '150px', align: 'right' },
  { title: '规格型号', dataIndex: 'specification', width: '150px', align: 'right' },
  { title: '单位', dataIndex: 'compositionQuantity', width: '100px', align: 'right' },
  { title: '出库数量', dataIndex: 'quantity', width: '100px', align: 'right' },
  {
    title: '出库金额',
    dataIndex: 'origTaxSaleAmount',
    width: '100px',
    align: 'right',
    hidden: true,
  },
  { title: '已开数量', dataIndex: 'Openedquantity', width: '100px', align: 'right' },
  { title: '签收数量', dataIndex: 'ReceivedQuantity', width: '100px', align: 'right' },
  {
    title: '开票使用名称',
    dataIndex: 'TM_Name',
    width: '300px',
    align: 'center',
    scopedSlots: { customRender: 'TM_Name' },
  },
  { title: '标准售价', dataIndex: 'origTaxSalePrice', width: '150px', align: 'right' },
  {
    title: '加成率%',
    dataIndex: 'markup',
    width: '100px',
    align: 'right',
    scopedSlots: { customRender: 'markup' },
  },
  {
    title: '开票价格',
    dataIndex: 'Price',
    width: '200px',
    align: 'right',
    scopedSlots: { customRender: 'Price' },
  },
  {
    title: '数量',
    dataIndex: 'numskk',
    width: '100px',
    align: 'right',
    scopedSlots: { customRender: 'numskk' },
  },
  { title: '含税金额', dataIndex: 'kmoneys', width: '150px', align: 'right' },
  {
    title: '税率%',
    dataIndex: 'TaxRate',
    width: '100px',
    align: 'right',
    scopedSlots: { customRender: 'TaxRate' },
  },
  { title: '税额', dataIndex: 'TaxPrice', width: '150px', align: 'right' },
]

export default {
  props: {
    parentObj: Object,
  },
  data() {
    return {
      tableWidth: 0,
      applyType: 0,
      columnsPreview,
      loadingPreview: false,
      data2Old: [],
      data: [],
      selectedRowKeys: [],
      pagination: {
        current: 1,
        pageSize: 25,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['25', '50', '100'], // 设置pageSize的可选值，页面可以通过下拉框进行选择
        showSizeChanger: true,
      },
      filters: {},
      sorter: { field: 'ID', order: 'desc' },
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 },
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: '',
    }
  },
  methods: {
    // 已申请未申请改变事件
    changeViewDataList() {
      this.data = this.data2Old.filter((item) => item.Id == this.applyType)
    },

    init() {
      this.visible = true
      this.data = []
      this.data2Old = []
      this.$nextTick(() => {
        // this.$refs['form'].clearValidate()
      })
    },
    openForm(record, title) {
      this.tableWidth = 1580
      console.log('传递过来的record', record, title)
      this.init()
      this.title = title
      this.loadingPreview = true
      this.$http.post('/InvoiceManagement/ST_RDRecord/GetBillInfoByState', { id: record.CODE }).then((resJson) => {
        if (resJson.Success) {
          this.loadingPreview = false
          console.log('成功了', resJson)
          let data = resJson.Data
          this.columnsPreview = data.columns
          this.columnsPreview.forEach((item) => {
            item.width = '150px'
            item.align = 'center'
          })
          this.data = data.datalist
          this.data2Old = JSON.parse(JSON.stringify(data.datalist))
          this.data = this.data.filter((item) => item.Id == this.applyType)
          this.loadingPreview = false
        }
        //
        // this.entity = resJson.Data.Maindata
        // this.data = resJson.Data.DetailsData
      })
      if (record.Id) {
        this.loading = true

        // this.$http
        //   .post('/OrderManagement/rdrecords32/GetDataList', {
        //     PageIndex: this.pagination.current,
        //     PageRows: 999,
        //     SortField: this.sorter.field || 'ID',
        //     SortType: this.sorter.order, DeptId: this.DeptId,
        //     Search: { Condition: 'ID', Keyword: id },
        //     ...this.filters
        //   })
        //   .then(resJson => {
        //     this.loading = false
        //     this.data = resJson.Data
        //     var iPrice = 0
        //     resJson.Data.forEach(item => {
        //       iPrice = item.iPrice + iPrice
        //     })
        //     const row = {
        //       iPrice,
        //       cInvCode: '合计'
        //     }
        //     this.data.push(row)
        //     if (this.data) {
        //       const pagination = { ...this.pagination }
        //       pagination.total = resJson.Total
        //       this.pagination = pagination
        //     }
        //   })
      }
    },
  },
}
</script>

<style lang="less" scoped>
/deep/.heji {
  position: sticky;
  bottom: 0;
  background: #fff;
  font-size: 19px;
  font-weight: bold;
}
</style>
